namespace Ds.DataBase.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class kaohefanwei : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.JiXiaoSons", "JiXiaoNeiRong_jxnrid", "dbo.JiXiaoNeiRongs");
            RenameColumn(table: "dbo.JiXiaoSons", name: "JiXiaoNeiRong_jxnrid", newName: "JiXiaoNeiRong_nrid");
            RenameIndex(table: "dbo.JiXiaoSons", name: "IX_JiXiaoNeiRong_jxnrid", newName: "IX_JiXiaoNeiRong_nrid");
            DropPrimaryKey("dbo.GongZuoJiHuaNeiRongs");
            DropPrimaryKey("dbo.JiXiaoNeiRongs");
            CreateTable(
                "dbo.NeiRongs",
                c => new
                    {
                        nrid = c.Int(nullable: false, identity: true),
                        nr = c.String(),
                        KaoHeFanWeiKeShi_khfwksi = c.Int(),
                    })
                .PrimaryKey(t => t.nrid)
                .ForeignKey("dbo.KaoHeFanWeiKeShis", t => t.KaoHeFanWeiKeShi_khfwksi)
                .Index(t => t.KaoHeFanWeiKeShi_khfwksi);
            
            CreateTable(
                "dbo.KaoHeFanWeiKeShis",
                c => new
                    {
                        khfwksi = c.Int(nullable: false, identity: true),
                        keShi_ksid = c.Int(),
                        KaoHeFanWei_khfwid = c.Int(),
                    })
                .PrimaryKey(t => t.khfwksi)
                .ForeignKey("dbo.KeShis", t => t.keShi_ksid)
                .ForeignKey("dbo.KaoHeFanWeis", t => t.KaoHeFanWei_khfwid)
                .Index(t => t.keShi_ksid)
                .Index(t => t.KaoHeFanWei_khfwid);
            
            CreateTable(
                "dbo.KaoHeFanWeis",
                c => new
                    {
                        khfwid = c.Int(nullable: false, identity: true),
                        username = c.String(),
                    })
                .PrimaryKey(t => t.khfwid);
            
            AddColumn("dbo.GongZuoJiHuaNeiRongs", "nrid", c => c.Int(nullable: false));
            AddColumn("dbo.JiXiaoNeiRongs", "nrid", c => c.Int(nullable: false));
            AddPrimaryKey("dbo.GongZuoJiHuaNeiRongs", "nrid");
            AddPrimaryKey("dbo.JiXiaoNeiRongs", "nrid");
            CreateIndex("dbo.GongZuoJiHuaNeiRongs", "nrid");
            CreateIndex("dbo.JiXiaoNeiRongs", "nrid");
            AddForeignKey("dbo.GongZuoJiHuaNeiRongs", "nrid", "dbo.NeiRongs", "nrid");
            AddForeignKey("dbo.JiXiaoNeiRongs", "nrid", "dbo.NeiRongs", "nrid");
            AddForeignKey("dbo.JiXiaoSons", "JiXiaoNeiRong_nrid", "dbo.JiXiaoNeiRongs", "nrid");
            DropColumn("dbo.GongZuoJiHuaNeiRongs", "gzjhnrid");
            DropColumn("dbo.GongZuoJiHuaNeiRongs", "gzjhnr");
            DropColumn("dbo.JiXiaoNeiRongs", "jxnrid");
            DropColumn("dbo.JiXiaoNeiRongs", "jxnr");
        }
        
        public override void Down()
        {
            AddColumn("dbo.JiXiaoNeiRongs", "jxnr", c => c.String());
            AddColumn("dbo.JiXiaoNeiRongs", "jxnrid", c => c.Int(nullable: false, identity: true));
            AddColumn("dbo.GongZuoJiHuaNeiRongs", "gzjhnr", c => c.String());
            AddColumn("dbo.GongZuoJiHuaNeiRongs", "gzjhnrid", c => c.Int(nullable: false, identity: true));
            DropForeignKey("dbo.JiXiaoSons", "JiXiaoNeiRong_nrid", "dbo.JiXiaoNeiRongs");
            DropForeignKey("dbo.JiXiaoNeiRongs", "nrid", "dbo.NeiRongs");
            DropForeignKey("dbo.GongZuoJiHuaNeiRongs", "nrid", "dbo.NeiRongs");
            DropForeignKey("dbo.KaoHeFanWeiKeShis", "KaoHeFanWei_khfwid", "dbo.KaoHeFanWeis");
            DropForeignKey("dbo.NeiRongs", "KaoHeFanWeiKeShi_khfwksi", "dbo.KaoHeFanWeiKeShis");
            DropForeignKey("dbo.KaoHeFanWeiKeShis", "keShi_ksid", "dbo.KeShis");
            DropIndex("dbo.JiXiaoNeiRongs", new[] { "nrid" });
            DropIndex("dbo.GongZuoJiHuaNeiRongs", new[] { "nrid" });
            DropIndex("dbo.KaoHeFanWeiKeShis", new[] { "KaoHeFanWei_khfwid" });
            DropIndex("dbo.KaoHeFanWeiKeShis", new[] { "keShi_ksid" });
            DropIndex("dbo.NeiRongs", new[] { "KaoHeFanWeiKeShi_khfwksi" });
            DropPrimaryKey("dbo.JiXiaoNeiRongs");
            DropPrimaryKey("dbo.GongZuoJiHuaNeiRongs");
            DropColumn("dbo.JiXiaoNeiRongs", "nrid");
            DropColumn("dbo.GongZuoJiHuaNeiRongs", "nrid");
            DropTable("dbo.KaoHeFanWeis");
            DropTable("dbo.KaoHeFanWeiKeShis");
            DropTable("dbo.NeiRongs");
            AddPrimaryKey("dbo.JiXiaoNeiRongs", "jxnrid");
            AddPrimaryKey("dbo.GongZuoJiHuaNeiRongs", "gzjhnrid");
            RenameIndex(table: "dbo.JiXiaoSons", name: "IX_JiXiaoNeiRong_nrid", newName: "IX_JiXiaoNeiRong_jxnrid");
            RenameColumn(table: "dbo.JiXiaoSons", name: "JiXiaoNeiRong_nrid", newName: "JiXiaoNeiRong_jxnrid");
            AddForeignKey("dbo.JiXiaoSons", "JiXiaoNeiRong_jxnrid", "dbo.JiXiaoNeiRongs", "jxnrid");
        }
    }
}
